<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/12/2
  Time: 10:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>数据统计</title>
    <script src="${pageContext.request.contextPath}/style/jquery-2.1.0.js"></script>
    <script src="${pageContext.request.contextPath}/style/echarts.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/style/layui/css/layui.css" charset="GBK">
    <script src="${pageContext.request.contextPath}/style/layui/layui.js"></script>
</head>
<style>
    #left {
        width: 58%;
        height: 450px;
        float: left;
    }

    #refresh {
        float: left;
        width: 2%;
    }

    #right {
        width: 40%;
        height: 450px;
        float: right;
    }
</style>
<body>
    <%--刷新按钮--%>
    <p onclick="refresh();" class="layui-icon layui-icon-refresh layui-anim layui-anim-scaleSpring"></p>
    <%--搜索条件表单--%>
    <form class="layui-form" id="searchForm">
        <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
            <div class="layui-inline">
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="year" id="year" placeholder="输入年份" class="layui-input">
                </div>
                <label class="layui-form-label">日期范围</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="monthMin" id="month1" placeholder="开始月份" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid">:</div>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="monthMax" id="month2" placeholder="结束月份" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width: 50px;">
                    <button type="button" onclick="getData();" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-normal">搜索</button>
                </div>
                <div class="layui-input-inline" style="width: 50px;">
                    <button type="reset" onclick="refresh();" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>

    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
    <div id="left"></div>
    <div id="right"></div>
</body>
<script type="text/javascript">
    $(function (){
        getData();
    });

    // 页面刷新按钮
    function refresh(){
        location=location;
        getData();
    }

    // 基于准备好的dom，初始化echarts实例
    var selectPrice = [];
    var monthData = [];
    function getData(){
        $.ajax({
            url: '${pageContext.request.contextPath}/count/selectPrice',
            type: 'post',
            data: $("#searchForm").serialize(),
            async: false,
            //dataType: 'json',
            success: function (result) {
                selectPrice = result.rukuMoney;
                monthData = result.monthData;
               /* alert(selectPrice)
                alert(monthData)*/
                begin();
            },error:function(msg){
                alert("服务器错误");
            }
        });
    }

    function begin() {
        var myChart = echarts.init(document.getElementById('left'));

        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '近一年营业的总金额'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            legend: {
                data: ['营业金额']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    boundaryGap: false,
                    data: monthData
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '营业金额',
                    type: 'line',
                    stack: '总量',
                    areaStyle: {},
                    data: selectPrice
                },
            ]
        };
        myChart.setOption(option);

        var sdata = [];
        $.ajax({
            url: '${pageContext.request.contextPath}/count/selectAll',
            data:$("#searchForm").serialize(),
            type: 'post',
            async: false,
            dataType: 'json',
            success: function (result) {
                //alert(JSON.stringify(result.name));
                sdata = result;
            },error:function(msg){
                alert("服务器错误");
            }
        });
        // 基于准备好的dom，初始化echarts实例
        var myChart2 = echarts.init(document.getElementById('right'));
        option2 = {

            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b}: {c} ({d}%)'
            },
            legend: {
                orient: 'vertical',
                left: 10,
                data:sdata
            },
            series: [
                {
                    name: '房间类型',
                    type: 'pie',
                    radius: ['50%', '70%'],
                    avoidLabelOverlap: false,
                    label: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        label: {
                            show: true,
                            fontSize: '30',
                            fontWeight: 'bold'
                        }
                    },
                    labelLine: {
                        show: false
                    },
                    data:sdata
                }
            ],
            title: {
                text: '                     各类房间营业额所占比',
            },
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart2.setOption(option2);
    }

</script>

<%--时间选择器--%>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#year' //指定元素
            , type: 'year'
            , calendar: true
        });
        laydate.render({
            elem: '#month1' //指定元素
            , format: 'MM'
            , type: 'month'
            , calendar: true
        });
        laydate.render({
            elem: '#month2' //指定元素
            , format: 'MM'
            , type: 'month'
            , calendar: true
        });
    });
</script>
</html>
